<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$aWhere = array();
if (reqVar('pagifilt')!='') {
	$aWhere[] = " uo.descr LIKE '%".addslashes(reqVar('pagifilt'))."%' "
		." OR uo.cod_uorg LIKE '%".addslashes(reqVar('pagifilt'))."%') ";
}
$sWhere = (count($aWhere)==0)? "":" WHERE ".implode(" AND ",$aWhere);
$sql_sel = "SELECT count(*) AS num_rec " .
		" FROM ovf_uorg uo " .$sWhere;
//dbg_($sql_sel);
$objDB->query($sql_sel,'selRec');
$acRec = $objDB->fetch('selRec');
$numRec = $acRec['num_rec'];
$link = $_SERVER['PHP_SELF']."?".$sXSNQS;
$startOffset = 0;
$endOffset = 0;
$sFiltro = ovfGetFiltro($link);
$sPaginaz = ovfGetPaginaz($link, $numRec, $startOffset, $endOffset);

$sql_sel = "SELECT uo.* FROM ovf_uorg uo " .
		" LEFT JOIN ovf_uorg uop ON uop.id_uorg = uo.id_uorg_padre ".
		" ORDER BY IFNULL(uop.cod_uorg, uo.cod_uorg), uo.id_uorg_padre, uo.cod_uorg ".
		" LIMIT ".$startOffset.",".($endOffset-$startOffset);
$objDB->query($sql_sel,'selRec');
$cmdL = "";
$cmdR = "&nbsp;&nbsp;&nbsp;";
if (true) {
	$cmdR .= "<a class=\"cmd1\" href=\"uorgIns.php?$sXSNQS\">nuova unita' org.</a>";
}
$cmdR .= cmdTorna(); 

testaHtml('Gestione unita\' organizzative','Lista unita\' organizzative', $msgPag, 'gest');
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('startoffset');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
   <tr>
      <td class="cmd1" align="left">
			<?=$sFiltro?>
      </td>
      <td class="cmd1" align="right">
			<?=$sPaginaz?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="lab1" width='20%' align='center' >Codice</td>
      <td class="lab1" width='80%' align='center'>Descrizione</td>
   </tr>
<? 
$clRF = 'txt2';
while($acX = $objDB->fetch('selRec')) { 
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
	if ($acX['id_uorg_padre']==0) { // area
?>
   <tr>
      <td class="<?=$clRF?>">
      	<a href='uorgMod.php?id=<?=$acX['id_uorg']."&$sXSNQS"?>' class="<?=$clRF?>"
      	 	style='font-family:lucida console,courier;'><?echo $acX['cod_uorg'];?></a>
      </td>
      <td class="<?=$clRF?>"><? echo $acX['descr'];?></td>
   </tr>
<? 
	} else { //filiale
?>
   <tr>
      <td class="<?=$clRF?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='uorgMod.php?id=<?=$acX['id_uorg']."&$sXSNQS"?>' class="<?=$clRF?>"
      	 	style='font-family:lucida console,courier;'><?echo $acX['cod_uorg'];?></a>
      </td>
      <td class="<?=$clRF?>"><? echo $acX['descr'];?></td>
   </tr>
<?php
	}
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right" colspan='2'>
<?=$sPaginaz?>
      </td>
   </tr>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
?>
